# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=jose
pkgname=haskell-jose
pkgver=0.10
pkgrel=44
pkgdesc="JSON Object Signing and Encryption (JOSE) and JSON Web Token (JWT) library"
url="https://github.com/frasertweedale/hs-jose"
license=("Apache")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-base64-bytestring' 'haskell-concise'
         'haskell-cryptonite' 'haskell-lens' 'haskell-memory' 'haskell-monad-time'
         'haskell-network-uri' 'haskell-x509')
makedepends=('ghc' 'haskell-hedgehog' 'haskell-hspec' 'haskell-pem' 'haskell-tasty'
             'haskell-tasty-hspec' 'haskell-tasty-hedgehog')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('fda1a9f7f856ad03e83771f490108f59629fab53a8ad9b582938ff5a766e8752b5f137348b4d2dd3744a7592268b8516a2a4789dbcc2e1a32e417bcf5c626d76')

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
